
//上传文件
 function fileupload(filepath,ajid,templateCode,fileTitle){  

	if(filepath!=""){    
		sendFileToServer(filepath,ajid,templateCode,fileTitle);  
	} else{  
		alert("请选择要上传的文件");  
		return;
	} 
}
//上传文书文件
 function fileuploaddoc(filepath,ajid,templateCode,fileTitle){  

	if(filepath!=""){    
		sendFileToServerdoc(filepath,ajid,templateCode,fileTitle);  
	} else{  
		alert("请选择要上传的文件");  
		return;
	} 
}

//文件写成流
function sendFileToServer(filePath,ajid,templateCode,fileTitle){ 
	var filepath=encodeURI(encodeURI(filePath));  
	var filetitle=encodeURI(encodeURI(fileTitle));  
	var stream =new ActiveXObject("ADODB.Stream");     
	stream.Type=1;     
	stream.Open();     
	stream.Position = 0;//指定或返加对像内数据的当前指针。
	stream.LoadFromFile(filePath) //将FileName指定的文件装入对像中,参数FileName为指定的用户名
	stream.Position = 0;
	//这里如果提交到action不能获取到前台的流 应该是struts拦截器的问题所以直接用jsp操作
	sendByteStreamToServer(stream,basepath+"/common/apabiPrint/fileupload.jsp?path="+filepath+
							"&ajid="+ajid+"&templateCode="+templateCode+"&fileTitle="+filetitle);//请求路径
	stream.Close();
}
//文书文件写成流
function sendFileToServerdoc(filePath,ajid,templateCode,fileTitle){ 
	var filepath=encodeURI(encodeURI(filePath));  
	var filetitle=encodeURI(encodeURI(fileTitle));  
	var stream =new ActiveXObject("ADODB.Stream");     
	stream.Type=1;     
	stream.Open();     
	stream.Position = 0;//指定或返加对像内数据的当前指针。
	stream.LoadFromFile(filePath) //将FileName指定的文件装入对像中,参数FileName为指定的用户名
	stream.Position = 0;
	//这里如果提交到action不能获取到前台的流 应该是struts拦截器的问题所以直接用jsp操作
	sendByteStreamToServerdoc(stream,basepath+"/common/apabiPrint/fileupload.jsp?path="+filepath+
							"&ajid="+ajid+"&templateCode="+templateCode+"&fileTitle="+filetitle);//请求路径
	stream.Close();
}


//文书盖章
function sendByteStreamToServerdoc(stream,url){  
	if (window.XMLHttpRequest) {      
		xmlhttp = new XMLHttpRequest();       
		if (xmlhttp.overrideMimeType) {          
			xmlhttp.overrideMimeType("text/xml")      
		}  
	} else if (window.ActiveXObject) {       
		var activexName = ["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];      
		for (var i = 0; i < activexName.length; i++) {          
			try {              
				xmlhttp = new ActiveXObject(activexName[i]);              
				break;          
			} catch(e) {               
				e.print()          
			}    
		} 
	} 
	xmlhttp.onreadystatechange = callbackdoc;  
	xmlhttp.open("post", url, false);  
	boundary="abcd"  
	xmlhttp.setRequestHeader("Content-Type", "multipart/form-data, boundary="+boundary);
	xmlhttp.setRequestHeader("Content-Length", stream.Size); 
	xmlhttp.send(stream); 
}


function sendByteStreamToServer(stream,url){  
	if (window.XMLHttpRequest) {      
		xmlhttp = new XMLHttpRequest();       
		if (xmlhttp.overrideMimeType) {          
			xmlhttp.overrideMimeType("text/xml")      
		}  
	} else if (window.ActiveXObject) {       
		var activexName = ["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];      
		for (var i = 0; i < activexName.length; i++) {          
			try {              
				xmlhttp = new ActiveXObject(activexName[i]);              
				break;          
			} catch(e) {               
				e.print()          
			}    
		} 
	} 
	xmlhttp.onreadystatechange = callback;  
	xmlhttp.open("post", url, false);  
	boundary="abcd"  
	xmlhttp.setRequestHeader("Content-Type", "multipart/form-data, boundary="+boundary);
	xmlhttp.setRequestHeader("Content-Length", stream.Size); 
	xmlhttp.send(stream); 
}


function callback() {   
	if (xmlhttp.readyState == 4) {       
		var responseText = xmlhttp.responseText; 
		if(xmlhttp.status==200){
			Ext.getBody().unmask();
			alert("盖章文件上传成功");
			//window.location.reload(); 
		}         
	}
}

//文书盖章
function callbackdoc() {   
	if (xmlhttp.readyState == 4) {       
		var responseText = xmlhttp.responseText; 
		if(xmlhttp.status==200){
			Ext.getBody().unmask();
			alert("盖章文件上传成功");
			window.location.reload(); 
		}         
	}
}




//删除文件
function deleteFile(){     
   var wshShell =new ActiveXObject("WScript.Shell");          
    //fso用来处理文件和文件夹   
    var fso = new ActiveXObject("Scripting.FileSystemObject");      
    //path删除文件的路径   
    var path = "c:\\temp";   
    //如果指定的文件夹存在则返回 True ；否则返回 False   
    if(fso.FolderExists(path)){   
      try{   
           fso.DeleteFile(path+"\\*.*");  
       }catch(e){   
             alert(".ceb" + e.message);   
       }     
   }else{   
           alert("不存在这个目录："+path);   
        }   
   } 